package com.fps.web.dao.impl;
import org.springframework.stereotype.Repository;
import com.fpswork.core.exception.exception.BusinessException;
import com.fpswork.core.model.PageEntity;
import com.fpswork.datamodel.basedao.BaseDao;
import com.fpswork.util.BeanUtils;
import com.fpswork.util.StringUtil;
import com.fps.web.dao.BasedictionaryDao;
import com.fps.web.model.Basedictionary;
@Repository 
public class BasedictionaryDaoImpl extends BaseDao implements BasedictionaryDao{
    
	public PageEntity queryBasedictionaryList(PageEntity pageEntity)  throws BusinessException{
		String sql="select * from basedictionary";
		pageEntity.setSql(sql);
		return  this.queryForPageEntity(pageEntity);
	}
	public Basedictionary queryBasedictionaryByID(String id)  throws BusinessException{
		return  this.get(Basedictionary.class, id);
	}
	public Basedictionary addBasedictionary(Basedictionary basedictionary)  throws BusinessException{
		//校验是否为空
		if(basedictionary==null){
			throw new BusinessException("传入数据为空！");
		}
		if(StringUtil.isEmpty(basedictionary.getId())){
			this.save(basedictionary);
		}else{
			throw new BusinessException("已存在数据！");
		}
		return basedictionary;
	}
	public Basedictionary updateBasedictionary(Basedictionary basedictionary)  throws BusinessException{
		Basedictionary basedictionary1= this.get(Basedictionary.class, basedictionary.getId());
		if(basedictionary1==null||StringUtil.isEmpty(basedictionary1.getId())){
	 		throw new BusinessException("没有找到数据！");
		}else{
			BeanUtils.copyProperties(basedictionary1, basedictionary);
			this.update(basedictionary1);
		}
		return basedictionary1;
	}
	public Boolean deleteBasedictionary(Basedictionary basedictionary)  throws BusinessException{
		this.delete(this.get(Basedictionary.class, basedictionary.getId()));
		
		return true;
	}
}
